// pages/mine/address_save.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region: [],customItem: '',tel:'',value:'',textarea:'',switch:false, phoneflag:''
  },

  
  onLoad: function (options) {

  },
//获取input输入框的值
   inputchange(e){
      if(e.detail.value==''){
        wx.showToast({
          title: '不能为空',
        })
      }
      const value=e.detail.value
      this.setData({
        value
      })
      
   },
   //获取联系电话的value
     inputchange1(e){
     
        this.checkMobile1(e.detail.value)
      
      
     },
     //获取详细地址的value
     inputchange2(e){
      if(e.detail.value==''){
        wx.showToast({
          title: '不能为空',
        })
      }
       const textarea=e.detail.value
       this.setData({
         textarea
       })
       
     }
,

  
  // 地址选择器
  bindRegionChange: function (e) {
    if(e.detail.value==''){
      wx.showToast({
        title: '不能为空',
      })
    }
    this.setData({
      region: e.detail.value
    })
    console.log('picker发送选择改变，携带值为', this.data.region)
  },
  //点击保存提交参数
  submit(){
     if(this.data.value==''||this.data.tel==''||this.data.textarea==''||this.data.region==''){
         return wx.showToast({
           title: '请填写完整',
         })
     }
       const uid=wx.getStorageSync('uid')||""
       if(uid==""){
       return  wx.showToast({
           title: '请先登录',
         })
       }
       const name=this.data.value
       const province=this.data.region[0]
       const city=this.data.region[1]
       const area=this.data.region[2]
       const address=this.data.textarea
       const phone=this.data.tel
       const type=this.data.switch==true?1:2
       const params={uid,province,city,address,area,phone,type,name}
       wx.request({
         url: 'https://zujieba.com/api/address/add_address.html',
         method:'POST',
         data:params,
         success:(res)=>{
           console.log(res);
           console.log(type);
           if(res.data.success==1){
            wx.navigateBack({
              complete: (res) => {},
            })
           }else{
             wx.showToast({
               title: res.data.tips,
               icon:'none'
             })
           }
           
         
         }
       })
       
  },
  switchchange(e){
    console.log(e);
    
     this.setData({
       switch:e.detail.value
     })
  },
  change8(e){
   let phoneflag=  this.checkMobile(e.detail.value)
   this.setData({
     tel:e.detail.value,
     phoneflag
   })
  },
  checkMobile1(e){
    
    if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(e))){
         wx.showToast({
           title: '手机输入不正确',
           icon:'none'
           
         })
        
        return false;
    }
    else{
      return true
    }
},
checkMobile(e){
    
  if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(e))){
      
      
      return false;
  }
  else{
    return true
  }
},
  
})